const { build } = require('tsup')
const path = require('path')

async function buildApp() {
    try {
        console.log('🚀 Building application...')

        await build({
            entry: ['src/app.ts'],
            format: ['cjs'],
            target: 'node18',
            outDir: 'dist',
            clean: true,
            sourcemap: true,
            minify: false,
            splitting: false,
            dts: false,
            external: [
                // 排除所有 node_modules 依赖
                /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/
            ],
            noExternal: [],
            platform: 'node'
        })

        console.log('✅ Build completed successfully!')
    } catch (error) {
        console.error('❌ Build failed:', error)
        process.exit(1)
    }
}

buildApp()
